<?php
// +----------------------------------------------------------------------
// | jpush [ NO ZUO NO DIE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2010-2015 http://www.jula.cc All rights reserved.
// +----------------------------------------------------------------------
// | Author: Hanj
// +----------------------------------------------------------------------
 
//----------------------------------
// TemplateMess-微信消息推送
//----------------------------------
class TemplateMess {
 
    private $temp_id = 'eFgjiHO5xmCW_YyMl4gJ21W5riuNmMAALbzUhTGbNGg';
 
    // public function __construct($config){
    //     $this->appKey       = $config['appKey'];
    //     $this->masterSecret = $config['appSecret'];
    // }
 
    /**
     * 根据手机号码及面额查询是否支持充值
     * @param  array  $aid     [用户aid数组,默认=all]
     * @param  string $title   [发送消息标题]
     * @param  string $msg     [发送消息]
     * @param  array  $extras  [推送结构]
     * @param  array  $platform[推送平台array('ios','android'),默认=all]
     * @return  boolean
     */
    public function send($openid = false, $url=fasle, $data=false,$temp_id=false){

        // 校验数据
        if (!$openid OR !$data) {
            
            return false;
        }
        $arr = array();
        $arr['touser']      = $openid;
        $arr['url']         =  $url ? $url : '';
        $arr['topcolor']    = '#000000';

        // 默认模版id
        if ($temp_id) {
            $arr['template_id'] = $temp_id;
        } else {
            $arr['template_id'] = $this->temp_id;
        }

        // {{first.DATA}}
        // 被推荐人：{{keyword1.DATA}}
        // 奖励金额：{{keyword2.DATA}}
        // 奖励时间：{{keyword3.DATA}}
        // {{remark.DATA}}
        $arr['data'] = $data;

        //加载微信SDK
        include LIBS_PATH."libraries/wechat.class.php";
        $wechat = new Wechat(array('appid'=>W_APPID,'appsecret'=>W_APPSECRET));
        // $access_token = $wechat->checkAuth();
        // $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
        return $wechat->sendTemplateMessage($arr);

    }
}